/**
 * \par Copyright (C), 2012-2016, MakeBlock
 * \class   Mecolor
 * \brief   Driver for GY33ColorSensor module.
 * @file    GY33ColorSensor.h
 * @author  MakeBlock
 * @version V1.0.2
 * @date    2017/01/17
 * @brief   Header for GY33ColorSensor.cpp module.
 *
 * \par Copyright
 * This software is Copyright (C), 2012-2016, MakeBlock. Use is subject to license \n
 * conditions. The main licensing options available are GPL V2 or Commercial: \n
 *
 * \par Open Source Licensing GPL V2
 * This is the appropriate option if you want to share the source code of your \n
 * application with everyone you distribute it to, and you also want to give them \n
 * the right to share who uses it. If you wish to use this software under Open \n
 * Source Licensing, you must contribute all your source code to the open source \n
 * community in accordance with the GPL Version 2 when your application is \n
 * distributed. See http://www.gnu.org/copyleft/gpl.html
 *
 * \par Description
 * This file is a drive for GY33ColorSensor module, It supports GY33ColorSensor V1.0 device provided
 * by MakeBlock.
 *
 * \par Method List:
 *
 *    1. void GY33ColorSensor::SensorInit(void)
 *    2. void GY33ColorSensor::ColorDataRead(void)
 *    4. void GY33ColorSensor::TurnOnLight(void)
 *    5. void GY33ColorSensor::TurnOffLight(void)
 *    6. uint16_t GY33ColorSensor::ReturnRedData(void)
 *    7. uint16_t GY33ColorSensor::ReturnGreenData(void)
 *    8. uint16_t GY33ColorSensor::ReturnBlueData(void)
 *    9. uint16_t GY33ColorSensor::ReturnClearData(void)
 *    10.uint8_t  GY33ColorSensor::ColorIdentify(void)
 *    11.long GY33ColorSensor::ReturnColorCode(void)
 *    14.int8_t GY33ColorSensor::writeReg(int16_t reg, uint8_t data)
 *    15.int8_t GY33ColorSensor::readData(uint8_t start, uint8_t *buffer, uint8_t size)
 *    16.int8_t GY33ColorSensor::writeData(uint8_t start, const uint8_t *pData, uint8_t size)
 *    17.uint8_t GY33ColorSensor::Returnresult(void);
 *    18.uint8_t GY33ColorSensor::ReturnGrayscale(void);
 *    19.uint16_t GY33ColorSensor::ReturnColorhue(void);
 *    20.uint8_t GY33ColorSensor::MAX(uint8_t r,uint8_t g,uint8_t b);
 *    21.uint8_t GY33ColorSensor::MIN(uint8_t r,uint8_t g,uint8_t b);
 *    22.void GY33ColorSensor::TurnOffmodule(void);
 *    23.void GY33ColorSensor::TurnOnmodule(void);
 * \par History:
 * <pre>
 * `<Author>`         `<Time>`        `<Version>`        `<Descr>`
 *  zzipeng         2017/01/17          1.0.0         complete the driver code.
 *  zzipeng         2017/04/03          1.0.1         only detect six colors.
 *  zzipeng         2017/04/10          1.0.2         only detect seven colors and add methods named GY33ColorSensor::TurnOffmodule(void),GY33ColorSensor::TurnOnmodule.
 * </pre>
 *
 */
#ifndef _GY33ColorSensor_H_
#define _GY33ColorSensor_H_

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#include <Arduino.h>
#include "MeConfig.h"
#include "Wire.h"

/* Exported macro ------------------------------------------------------------*/
#define I2C_ERROR                       (-1)
#define COLORSENSOR_DEFAULT_ADDRESS     (0xB4)
/* register List  ------------------------------------------------------------*/
#define RAW_RED_H       (0X00)
#define RAW_RED_L       (0X01)
#define RAW_GREEN_H     (0X02)
#define RAW_GREEN_L     (0X03)
#define RAW_BLUE_H      (0X04)
#define RAW_BLUE_L      (0X05)
#define RAW_CLEAR_H     (0X06)
#define RAW_CLEAR_L     (0X07)
#define LUX_H           (0X08)
#define LUX_L           (0X09)
#define COLOR_TEMPR_H   (0X0A)
#define COLOR_TEMPR_L   (0X0B)
#define COLOR_R         (0X0C)
#define COLOR_G         (0X0D)
#define COLOR_B         (0X0E)
#define COLOR_NUM       (0X0F)
#define MODULE_CONFIG   (0X10)

/*RGB list*/
typedef enum
{
  WHITE=0,
  PINKE,
  RED,
  ORANGE,
  YELLOW,
  GREEN,
  CYAN,
  BLUE,
  PURPLE,
  BLACK,
  GOLD,
}COLORTYPES;
/*
 * Class: GY33ColorSensor
 * \par Description
 * Declaration of Class GY33ColorSensor
 */

class GY33ColorSensor
{
public:
  GY33ColorSensor(void);
  GY33ColorSensor(uint8_t address);
  void SensorInit(void);
  uint8_t ColorIdentify(void);
  void ConfigLight(void);
  int8_t writeReg(int16_t reg, uint8_t data);
  int8_t readData(uint8_t start, uint8_t *buffer, uint8_t size);
  int8_t writeData(uint8_t start, const uint8_t *pData, uint8_t size);
  void update();
  void doWhiteBalance();
  int8_t getColor();

/***********************************/
private:
  uint8_t m_Device_Address;
  uint16_t m_OrigRedvalue;
  uint16_t m_OrigGreenvalue;
  uint16_t m_OrigBluevalue;
  uint16_t m_OrigClearvalue;
  uint8_t m_Red;
  uint8_t m_Green;
  uint8_t m_Blue;
};
#endif

